
/**
 * A Bank class
 * @author Sanjeev Kamboj, Travis Drake
 * Assignment 1
 *
 */
public class DebitCard 
{
	/** Static int to keep track of Debit Card numbers issued*/
	private static int fLastDebitCardNumber = 1;
	
	/** The Checking Account that this DebitCard is linked to.*/
	private CheckingAccount fAccountConnectedTo;
	
	/** The DebitCard number */
	private int fDebitCardNumber;
	
	/**The owner the debitCard.*/
	private Person my_owner;
	
	/**
	 * Constructs a Debit Card
	 * 
	 * @param name The name of the owner
	 * @param street The street of the owner
	 * @param town The town of the owner
	 * @param zipCode The zipcode of the owner
	 * @param country The country of the owner.
	 */
	public DebitCard(final Person the_person)
	{
		
		this(the_person, 0, new CheckingAccount(the_person));
	}
	
	/**
	 * Constructs a DebitCard
	 * 
	 * @param name The name of the owner
	 * @param street The street of the owner
	 * @param town The town of the owner
	 * @param zipCode The zipcode of the owner
	 * @param country The country of the owner.
	 * @param limit The debit card limit
	 * @param account The checkAccount to link to 
	 */
	public DebitCard(final Person the_owner, double limit, CheckingAccount account)
	{
		my_owner = the_owner;
		fDebitCardNumber = fLastDebitCardNumber;
		fLastDebitCardNumber++;
		fAccountConnectedTo = account;
	}
	
	/**
	 * Method that pays off the Debit Card.
	 * 
	 * @param amount The amount paying off
	 * @return boolean for if the payment was made.
	 */
	public boolean pay(double amount)
	{
		boolean is_payed = false;
		double next_balance = fAccountConnectedTo.getBalance() - amount;
		
		if(next_balance > -fAccountConnectedTo.getDebitAmount())
		{
			fAccountConnectedTo.setBalance(next_balance);
			is_payed = true;
		}
		return is_payed;
	}
	
	/**
	 * Getter for Account Number
	 * @return An int for the account number.
	 */
	public int getAccountNum() {
		return fDebitCardNumber;
	}
	
	/**
	 * Getter for the owner's name.
	 * @return String for the name of the owner.
	 */
	public String getName() {
		return my_owner.getName();
	}
	
	/**Made for testing purposes*/
	protected int getCheckAcctNum() {
		return fAccountConnectedTo.getAccountNumber();
	}

}
